home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / rbbs_pc / node2src.zip / RBBSSUB6.BAS < prev    next >
BASIC Source File  |  1990-03-25  |  37KB  |  1,284 lines

  1. '*
  2. '*  ANSIED v2.42
  3. '*---------------------------------------------------------------------------
  4. '*  Full Screen Text Editor for RBBS-PC
  5. '*  QuickBASIC v3.0 Version
  6. '*  02-14-90
  7. '*
  8. '* Changes from the QB 4.5 Version are marked with the
  9. '* comment "QB 3.0 Mod"
  10. '*
  11. '*  v2.1xx ... made it work with RBBS v17
  12. '*  v2.2 ... fixed some inconsistincies in the code as to # of lines in msg.
  13. '*           Some of the code thought 99 was length, some thought 100.
  14. '*  v2.3 .. let it work with quoted reply.  No more REDIM of ZOutTxt$
  15. '*  v2.4 .. removed tabs, margins code to be smaller
  16. '*  v2.41.. fixed bug with loss of bold attribute occasionally
  17. '*  v2.42.. made it work as a v17.3 subroutine.  Added block delete.
  18. '*
  19. '*  Returns:
  20. '*  ZSubParm  =  1 - Save Message
  21. '*            =  2 - Abort Message
  22. '*            = -1 - Dropped Carrier
  23. '*            = -2 - Sleep Disconnect
  24. '*
  25.  
  26. '  $INCLUDE: 'RBBS-VAR.MOD'
  27.  
  28.  
  29. 10 DEFINT A-Z
  30.  
  31. 13    COMMON SHARED /Ansied/ CurrentRow, CurrentCol, TopLine
  32.       COMMON SHARED /Ansied/ OldColour, IsBold, InsertMode
  33.       COMMON SHARED /Ansied/ BlankLine$, SoftSpace$, ESCKey$, CarrRet$
  34.       COMMON SHARED /Ansied/ ColLeftKey$, ColRightKey$, HomeKey$, EndKey$
  35.       COMMON SHARED /Ansied/ PageUpKey$, PageDownKey$, LineUpKey$
  36.       COMMON SHARED /Ansied/ LineDownKey$, HelpKey$, ReformTextKey$
  37.       COMMON SHARED /Ansied/ ReflowTextKey, EndSessionKey$, ToggleINSKey$
  38.       COMMON SHARED /Ansied/ RepaintKey$, BlockDelActive
  39.       COMMON SHARED /Ansied/ BlockLine1, BlockLine2
  40.       COMMON SHARED /Ansied/ YellowFore, CyanFore, WhiteFore
  41.  
  42. SUB Ansied STATIC
  43.  
  44.       REDIM ZWorkAra$(24)             ' Top 24 lines of screen (bottom line
  45.                       ' used by comm program, top line =
  46.                       ' (1) used for menu)
  47. 14    ESCKey$ = CHR$(27)
  48.       BackspKey$ = CHR$(8)
  49.       OtherBackspKey$ = CHR$(127)
  50.       TabKey$ = CHR$(9)
  51.       DelKey$ = CHR$(127)
  52.       CarrRet$ = CHR$(13)
  53.       ZLineFeed$ = CHR$(10)
  54.       LineUpKey$ = CHR$(5)        ' Ctrl-E
  55.       LineDownKey$ = CHR$(24)     ' Ctrl-X
  56.       ColLeftKey$ = CHR$(19)      ' Ctrl-S
  57.       ColRightKey$ = CHR$(4)      ' Ctrl-D
  58.       WordLeftKey$ = CHR$(1)      ' Ctrl-A
  59.       WordRightKey$ = CHR$(6)     ' Ctrl-F
  60.       PageUpKey$ = CHR$(18)       ' Ctrl-R
  61.       PageDownKey$ = CHR$(3)      ' Ctrl-C
  62.       HomeKey$ = CHR$(23)         ' Ctrl-W
  63.       EndKey$ = CHR$(26)          ' Ctrl-Z
  64.       RepaintKey$ = CHR$(16)      ' Ctrl-P
  65.       LineDeleteKey$ = CHR$(25)   ' Ctrl-Y
  66.       CharDeleteKey$ = CHR$(7)    ' Ctrl-G
  67.       ReformTextKey$ = CHR$(2)    ' Ctrl-B
  68.       ReflowTextKey$ = CHR$(15)   ' Ctrl-O
  69.       ToggleINSKey$ = CHR$(22)    ' Ctrl-V
  70.       EndSessionKey$ = CHR$(11)   ' Ctrl-K
  71.       HelpKey$ = CHR$(14)         ' Ctrl-N
  72.  
  73.       SoftSpace$ = CHR$(250)
  74.       
  75. 15    BlankLine$ = ""
  76.       
  77.       InsertMode = ZTrue
  78.       ZRightMargin = 75
  79.       OldColour = 0
  80.       Bold = ZFalse
  81.       IsBold = 99                 ' v2.41
  82.       BlockDelActive = ZFalse
  83.       CurrentCol = 0
  84.       CurrentRow = 0
  85.       TopLine = 1           ' Line of ZOutTxt$ that corresponds to the top of
  86.                 ' the displayed image (1..12..23..34..45..56..78)
  87.  
  88.       BlockDelKeys$ = ESCKey$ + LineUpKey$ + LineDownKey$ + PageUpKey$ + PageDownKey$ + CarrRet$
  89.  
  90. 16    FOR I = 1 TO 24
  91.       ZWorkAra$(I) = BlankLine$
  92.       NEXT I
  93.  
  94.       '*
  95.       '* Initialize the screen    'Pe 03/22/90
  96.       '*
  97.  
  98. 17  IF ZFG4$ <> "" THEN  
  99.      YellowFore = 33 
  100.      CyanFore = 36 
  101.      WhiteFore = 37
  102. Else
  103.      YellowFore = 37 
  104.      CyanFore = 37 
  105.      WhiteFore = 37
  106. END IF
  107.  
  108.       CALL ClearScreen
  109.       CALL ClearMainMenu
  110.       CALL UpdateStatusLine
  111.       CALL UpdateScreen   ' v2.3
  112.       CALL MoveCursor(2, 1)
  113.  
  114.       '*
  115.       '* Run the Editor
  116.       '*
  117.  
  118. 18    WHILE 1
  119.  
  120.      CALL Carrier
  121.      IF ZSubParm = -1 THEN GOTO 1001
  122.      CALL Getch(B$)
  123.      IF ZSubParm <> 0 THEN GOTO 1001
  124.  
  125. 19       IF B$ = ESCKey$ THEN
  126.         IF BlockDelActive THEN
  127.            BlockDelActive = ZFalse
  128.            CALL SaveCursor(RowSave, ColSave)
  129.            CALL UpdateStatusLine
  130.            CALL MoveCursor(RowSave, ColSave)
  131.                B$ = CHR$(255)
  132.         ELSE
  133.            CALL Getch(B$)
  134.            IF ZSubParm <> 0 THEN GOTO 1001
  135.            IF B$ = "[" THEN           ' ANSI sequence
  136.           CALL Getch(B$)
  137.           IF ZSubParm <> 0 THEN GOTO 1001
  138.           IF B$ = "C" THEN
  139.              B$ = ColRightKey$
  140.           ELSEIF B$ = "D" THEN
  141.              B$ = ColLeftKey$
  142.           ELSEIF B$ = "A" THEN
  143.              B$ = LineUpKey$
  144.           ELSEIF B$ = "B" THEN
  145.              B$ = LineDownKey$
  146.           END IF
  147.            END IF
  148.         END IF
  149.      END IF
  150.  
  151.      IF BlockDelActive AND INSTR(BlockDelKeys$, B$) = 0 THEN
  152.  
  153.      ELSEIF BlockDelActive AND B$ = CarrRet$ THEN
  154.  
  155.         CALL CarrRetKey
  156.         CALL MoveCursor(RowSave, ColSave)
  157.  
  158.      ELSEIF B$ = ESCKey$ THEN
  159.  
  160.             '*
  161.             '* User wants to see main menu
  162.             '*
  163.  
  164.             CALL SaveCursor(RowSave,ColSave)
  165.             CALL ClearMainMenu
  166.             CALL DisplayMainMenu
  167.             CALL MoveCursor(RowSave, ColSave)
  168.  
  169. 20          B$ = ""
  170.             WHILE B$ <> ESCKey$ AND B$ <> "B"
  171.  
  172.                CALL Getch(B$)
  173.                IF ZSubParm <> 0 THEN GOTO 1001
  174.                CALL AllCaps(B$)                                    ' QB 3.0 Mod
  175.  
  176.                IF B$ = CarrRet$ THEN
  177.                   CALL ExecuteMainMenuCommand("H")
  178.                   IF ZSubParm = -1 THEN GOTO 1001
  179.                   B$ = ESCKey$
  180.                ELSEIF INSTR("HJREIPB", B$) <> 0 THEN
  181.                   IF B$ = "B" THEN
  182.                      BlockDelActive = ZTrue
  183.                      BlockLine1 = RowSave + TopLine - 2
  184.                      CALL ClearMainMenu
  185.                      CALL Puts("Block Delete: Move cursor to last line to delete and press [ENTER], ESC Quits", YellowFore, ZFalse)
  186.                      CALL MoveCursor(RowSave, ColSave)
  187.                      BlockLine2 = 0
  188.                   ELSE
  189.                      CALL ExecuteMainMenuCommand(B$)
  190.                      IF ZSubParm <> 0 THEN GOTO 1001
  191.                      B$ = ESCKey$
  192.                   END IF
  193.                END IF
  194.  
  195.             WEND
  196.  
  197.             IF B$ <> "B" THEN
  198.                CALL ClearMainMenu
  199.                CALL UpdateStatusLine
  200.             END IF
  201.  
  202.             CALL MoveCursor(RowSave, ColSave)
  203.  
  204.      ELSEIF B$ = LineUpKey$ THEN
  205.  
  206.             '*
  207.             '* Move the current cursor position up one line
  208.             '*
  209.  
  210.         IF CurrentRow > 2 THEN
  211.            CALL MoveCursor(CurrentRow - 1, CurrentCol)
  212.         ELSE
  213.            IF TopLine <> 1 THEN
  214.           TopLine = TopLine - 11
  215.           CALL MoveCursor(CurrentRow + 10, CurrentCol)
  216.            END IF
  217.            CALL UpdateScreen
  218.         END IF
  219.  
  220.      ELSEIF B$ = LineDownKey$ THEN
  221.  
  222.             '*
  223.             '* Move the current cursor position down one line
  224.             '*
  225.  
  226.         IF CurrentRow < 23 THEN
  227.            CALL MoveCursor(CurrentRow + 1, CurrentCol)
  228.         ELSE
  229.            IF NOT TopLine = 78 THEN
  230.           TopLine = TopLine + 11
  231.           CALL MoveCursor(CurrentRow - 10, CurrentCol)
  232.           CALL UpdateScreen
  233.            END IF
  234.         END IF
  235.  
  236.      ELSEIF B$ = ColLeftKey$ THEN
  237.  
  238.             '*
  239.             '* Move the current cursor left one column
  240.             '*
  241.  
  242.         IF CurrentCol > 1 THEN CALL MoveCursor(CurrentRow, CurrentCol - 1)
  243.  
  244.      ELSEIF B$ = ColRightKey$ THEN
  245.  
  246.             '*
  247.             '* Move the current cursor right one column
  248.             '*
  249.  
  250.         IF CurrentCol < 79 THEN CALL MoveCursor(CurrentRow, CurrentCol + 1)
  251.  
  252.      ELSEIF B$ = WordRightKey$ THEN
  253.  
  254.             '*
  255.             '* Move the current cursor right one word
  256.             '*
  257.  
  258.         Index = CurrentRow + TopLine - 2
  259.  
  260.         FOR I = CurrentCol TO LEN(ZOutTxt$(Index)) - 1
  261.  
  262.            YY$ = MID$(ZOutTxt$(Index), I, 1)
  263.            ZZ$ = MID$(ZOutTxt$(Index), I + 1, 1)
  264.            IF (YY$ = " " OR YY$ = SoftSpace$) AND ZZ$ <> " " AND ZZ$ <> SoftSpace$ THEN
  265.           Newcol = I + 1
  266.           IF Newcol > 79 THEN Newcol = 79
  267.           CALL MoveCursor(CurrentRow, Newcol)
  268.           EXIT FOR
  269.            END IF
  270.  
  271.         NEXT I
  272.  
  273.      ELSEIF B$ = WordLeftKey$ THEN
  274.  
  275.             '*
  276.             '* Move the current cursor left one word
  277.             '*
  278.  
  279.         Index = CurrentRow + TopLine - 2
  280.  
  281.         Found = ZFalse
  282.         FOR I = CurrentCol - 1 TO 2 STEP -1
  283.  
  284.            ZZ$ = MID$(ZOutTxt$(Index), I, 1)
  285.            YY$ = MID$(ZOutTxt$(Index), I - 1, 1)
  286.            IF (YY$ = " " OR YY$ = SoftSpace$) AND ZZ$ <> " " AND ZZ$ <> SoftSpace$ THEN
  287.           Newcol = I
  288.           CALL MoveCursor(CurrentRow, Newcol)
  289.           Found = ZTrue
  290.           EXIT FOR
  291.            END IF
  292.  
  293.         NEXT I
  294.         IF NOT Found THEN
  295.            CALL MoveCursor(CurrentRow, 1)
  296.         END IF
  297.  
  298.      ELSEIF B$ = HomeKey$ THEN
  299.  
  300.             '*
  301.             '* Move cursor to the start of the line
  302.             '*
  303.  
  304.         CALL MoveCursor(CurrentRow, 1)
  305.  
  306.      ELSEIF B$ = EndKey$ THEN
  307.  
  308.             '*
  309.             '* Move cursor to the end of the line
  310.             '*
  311.  
  312.         Index = CurrentRow + TopLine - 2
  313.         IF ZOutTxt$(Index) = STRING$(79, 250) THEN
  314.            Newcol = 1
  315.         ELSE
  316.            Newcol = 0
  317.            FOR I = LEN(ZOutTxt$(Index)) TO 1 STEP -1
  318.           IF MID$(ZOutTxt$(Index), I, 1) <> SoftSpace$ THEN
  319.              Newcol = I + 1
  320.              EXIT FOR
  321.           END IF
  322.            NEXT I
  323.            IF Newcol > 79 THEN
  324.           Newcol = 79
  325.            ELSEIF Newcol < 1 THEN
  326.           Newcol = 1
  327.            END IF
  328.         END IF
  329.         CALL MoveCursor(CurrentRow, Newcol)
  330.  
  331.      ELSEIF B$ = PageDownKey$ THEN
  332.  
  333.             '*
  334.             '* Move the display one page down
  335.             '*
  336.  
  337.         TopLine = TopLine + 22
  338.         IF TopLine > 78 THEN TopLine = 78
  339.         CALL UpdateScreen
  340.  
  341.      ELSEIF B$ = PageUpKey$ THEN
  342.  
  343.             '*
  344.             '* Move the display one page up
  345.             '*
  346.  
  347.         TopLine = TopLine - 22
  348.         IF TopLine < 1 THEN TopLine = 1
  349.         CALL UpdateScreen
  350.  
  351.      ELSEIF B$ = LineDeleteKey$ THEN
  352.  
  353.             '*
  354.             '* Delete the current line in the file
  355.             '*
  356.  
  357.             CALL SaveCursor(RowSave,ColSave)
  358.         CALL DeleteCurrentLine
  359.         CALL MoveCursor(RowSave, ColSave)
  360.  
  361.      ELSEIF B$ = CharDeleteKey$ THEN
  362.  
  363.             '*
  364.             '* Delete the current character
  365.             '*
  366.  
  367.         Index = CurrentRow + TopLine - 2
  368.         IF CurrentCol <= LEN(ZOutTxt$(Index)) THEN
  369.            CALL MoveCursor(CurrentRow, CurrentCol + 1)
  370.            CALL BackspChar
  371.         END IF
  372.  
  373.      ELSEIF B$ = BackspKey$ OR B$ = OtherBackspKey$ THEN
  374.  
  375.             '*
  376.             '* Back up one character and destroy it
  377.             '*
  378.  
  379.         CALL BackspChar
  380.  
  381.      ELSEIF B$ = CarrRet$ THEN
  382.  
  383.             '*
  384.             '* Move to the next line, col LM
  385.             '*
  386.  
  387.             CALL CarrRetKey
  388.  
  389.      ELSEIF B$ = HelpKey$ OR B$ = ReformTextKey$ OR B$ = ReflowTextKey$ OR B$ = EndSessionKey$ OR B$ = ToggleINSKey$ OR B$ = RepaintKey$ THEN
  390.  
  391.             '*
  392.             '* Execute a main menu command
  393.             '*
  394.  
  395.             YY$ = HelpKey$ + ReformTextKey$ + ReflowTextKey$ + EndSessionKey$ + ToggleINSKey$ + RepaintKey$
  396.  
  397.             I = INSTR(YY$, B$)
  398.             CALL SaveCursor(RowSave,ColSave)
  399.             CALL ExecuteMainMenuCommand(MID$("HJREIP", I, 1))
  400.             IF ZSubParm <> 0 THEN GOTO 1001
  401.             CALL UpdateStatusLine
  402.             CALL MoveCursor(RowSave, ColSave)
  403.  
  404.      ELSEIF ASC(B$) > 127 OR ASC(B$) < 32 THEN
  405.  
  406.             '*
  407.             '* Ignore characters above 127 or below 32
  408.             '*
  409.  
  410.      ELSE
  411.  
  412.             '*
  413.             '* Input was a normal character
  414.             '*
  415.  
  416.         CALL NormalChar(B$)
  417.  
  418.      END IF
  419.  
  420.       WEND
  421.  
  422. 1001  REDIM ZWorkAra$(13)
  423.  
  424. END SUB         ' Sub AnsiEd
  425.  
  426. '*----------------------------------------------------------------------------*
  427. '*  This routine handles the user entering the backspace key                  *
  428. '*----------------------------------------------------------------------------*
  429. SUB BackspChar STATIC
  430.  
  431.       CALL SaveCursor(RowSave,ColSave)
  432.  
  433.       Index = TopLine + CurrentRow - 2
  434.       IF Index = 1 AND CurrentCol = 1 AND CurrentRow = 2 THEN EXIT SUB
  435.  
  436. 2101  AtEndOfLine = CurrentCol > LEN(ZOutTxt$(Index))
  437.  
  438.       IF CurrentCol > 1 THEN
  439.  
  440. 2102     ZOutTxt$(Index) = LEFT$(ZOutTxt$(Index), CurrentCol - 2) + MID$(ZOutTxt$(Index), CurrentCol)
  441.      CALL EraseToEOL(CurrentRow, CurrentCol - 1)
  442.      IF NOT AtEndOfLine THEN
  443.         YY$ = MID$(ZOutTxt$(Index), ColSave - 1)
  444.         CALL MoveCursor(RowSave, ColSave - 1)
  445.         CALL Puts(YY$, YellowFore, ZTrue)
  446.      END IF
  447.      CALL MoveCursor(RowSave, ColSave - 1)
  448.      ZWorkAra$(CurrentRow) = ZOutTxt$(Index)
  449.  
  450.       ELSEIF LEN(ZOutTxt$(Index - 1)) >= ZRightMargin THEN
  451.  
  452.       ELSE
  453.  
  454.      Newcol = LEN(ZOutTxt$(Index - 1)) + 1
  455.      YY$ = ZOutTxt$(Index)
  456.      CALL NoSoft(YY$)
  457.      ZOutTxt$(Index - 1) = ZOutTxt$(Index - 1) + YY$
  458.      IF LEN(ZOutTxt$(Index - 1)) < ZRightMargin THEN
  459.         FOR I = Index TO 98        ' v2.2
  460.            ZOutTxt$(I) = ZOutTxt$(I + 1)
  461.         NEXT I
  462.         ZOutTxt$(99) = BlankLine$       ' v2.2
  463.      ELSE
  464.         CALL FindWrap(LEFT$(ZOutTxt$(Index - 1), ZRightMargin + 1), I)
  465.         IF I = 0 OR I = 1 THEN I = ZRightMargin
  466.         ZOutTxt$(Index) = MID$(ZOutTxt$(Index - 1), I + 1)
  467.         ZOutTxt$(Index - 1) = LEFT$(ZOutTxt$(Index - 1), I)
  468.      END IF
  469.      IF RowSave > 2 THEN
  470.         CALL MoveCursor(RowSave - 1, Newcol)
  471.         CALL UpdateScreen
  472.      ELSE
  473.         CALL MoveCursor(RowSave, Newcol)
  474.         CALL Ungetch(LineUpKey$)
  475.      END IF
  476.  
  477.       END IF
  478.  
  479. END SUB
  480.  
  481. '*----------------------------------------------------------------------------*
  482. '*  This routine handles carriage returns entered in the file                 *
  483. '*----------------------------------------------------------------------------*
  484. SUB CarrRetKey STATIC
  485.  
  486.       IF BlockDelActive THEN
  487.      BlockDelActive = ZFalse
  488.      Index = CurrentRow + TopLine - 2
  489.      BlockLine2 = Index
  490.      IF Index < BlockLine1 THEN
  491.         BlockLine2 = BlockLine1
  492.         BlockLine1 = Index
  493.      END IF
  494.      K = 0
  495.      FOR I = BlockLine2 + 1 TO 99
  496.         ZOutTxt$(BlockLine1 + K) = ZOutTxt$(I)
  497.         K = K + 1
  498.      NEXT I
  499.          WHILE BlockLine1 + K <= 99
  500.             ZOutTxt$(BlockLine1 + K) = BlankLine$
  501.             K = K + 1
  502.          WEND
  503.      CALL UpdateScreen
  504.      CALL UpdateStatusLine
  505.      EXIT SUB
  506.       END IF
  507.  
  508. 2000  Index = CurrentRow + TopLine - 2
  509.       IF Index >= 99 THEN EXIT SUB  ' v2.2
  510.       IF InsertMode THEN         ' Insert a new line
  511.      FOR I = 98 TO Index + 1 STEP -1  ' v2.2
  512.         ZOutTxt$(I + 1) = ZOutTxt$(I)
  513.      NEXT I
  514.      IF LEN(ZOutTxt$(Index)) >= CurrentCol THEN
  515.         ZOutTxt$(Index + 1) = MID$(ZOutTxt$(Index), CurrentCol)
  516.         ZOutTxt$(Index) = LEFT$(ZOutTxt$(Index), CurrentCol - 1)
  517.      ELSE
  518.         ZOutTxt$(Index + 1) = ""
  519.      END IF
  520.      CALL UpdateScreen
  521.       END IF
  522.       IF CurrentRow < 23 THEN
  523.      CALL MoveCursor(CurrentRow + 1, 1)
  524.       ELSE
  525.      CALL MoveCursor(CurrentRow, 1)
  526.      CALL Ungetch(LineDownKey$)
  527.       END IF
  528.  
  529. END SUB
  530.  
  531. '*----------------------------------------------------------------------------*
  532. '*           This routine clears a line from the screen                       *
  533. '*----------------------------------------------------------------------------*
  534. SUB ClearLine (LineNumber) STATIC
  535.  
  536.       CALL EraseToEOL(LineNumber, 1)
  537.  
  538. END SUB
  539.  
  540. '*----------------------------------------------------------------------------*
  541. '*           This routine clears the main menu from the top line              *
  542. '*----------------------------------------------------------------------------*
  543. SUB ClearMainMenu STATIC
  544.  
  545.       CurrentRow = 0
  546.       CurrentCol = 0
  547.       CALL EraseToEOL(1, 1)
  548.  
  549. END SUB
  550.  
  551. '*----------------------------------------------------------------------------*
  552. '*  This routine clears the screen and moves the cursor to row 2, col 1       *
  553. '*----------------------------------------------------------------------------*
  554. SUB ClearScreen STATIC
  555.  
  556.       CurrentRow = 0
  557.       CurrentCol = 0
  558. 300   ZZ$ = "H"      ' clear screen, column 1, row 2
  559.       FOR I = 1 TO 23
  560.      ZWorkAra$(I) = BlankLine$
  561.       NEXT I
  562.       CALL Puts(ZZ$, 99, ZFalse)
  563.       ZSubParm = 2
  564.       CALL Line25
  565.       ZSubParm = 0
  566.       CurrentCol = 1
  567.       CurrentRow = 2
  568.       IsBold = 99          ' v2.41
  569.  
  570.       CALL MoveCursor(2, 1)
  571.  
  572. END SUB
  573.  
  574. '*----------------------------------------------------------------------------*
  575. '*  This routine deletes the current line on the screen and in the array      *
  576. '*  ZOutTxt$, and moves the next lower line up one  It then repaints the      *
  577. '*  affected portion of the screen (from the deleted line down)               *
  578. '*----------------------------------------------------------------------------*
  579. SUB DeleteCurrentLine STATIC
  580.  
  581. 1900  Index = TopLine + CurrentRow - 2
  582.       FOR I = Index TO 98
  583.      ZOutTxt$(I) = ZOutTxt$(I + 1)
  584.       NEXT I
  585.       ZOutTxt$(99) = BlankLine$
  586.       CALL UpdateScreen
  587.  
  588. END SUB
  589.  
  590. '*----------------------------------------------------------------------------*
  591. '*        This routine displays the main menu on the top line                 *
  592. '*----------------------------------------------------------------------------*
  593. SUB DisplayMainMenu STATIC
  594.  
  595.       CurrentRow = 0
  596.       CurrentCol = 0
  597. 700   CALL MoveCursor(1, 1)
  598.       CALL QuickTput(ZEmphasizeOff$, 0)
  599.       YY$ = "Main Menu: [H]elp E)nd R)eflow J)ustify I)ns/Ovw P)aint B)lock Del   ESC Quits"
  600.       YY$ = YY$ + SPACE$(79 - LEN(YY$))
  601.       ZHiLiteOff = ZFalse
  602.       CALL ColorPrompt(YY$)
  603.       CALL Puts(YY$, 99, ZTrue)
  604.       IsBold = 99                  ' v2.41
  605.       CurrentRow = 0
  606.       CurrentCol = 0
  607.  
  608. END SUB
  609.  
  610. '*----------------------------------------------------------------------------*
  611. '*  This routine is called to save or abort the msg                           *
  612. '*----------------------------------------------------------------------------*
  613. SUB DoneWithMsg STATIC
  614.  
  615. 2300  CALL SaveCursor(RowSave,ColSave)
  616.       CALL ClearMainMenu
  617.       CALL QuickTput(ZEmphasizeOff$, 0)
  618.       CurrentRow = 0
  619.       CurrentCol = 0
  620.       CALL MoveCursor(1, 1)
  621.       YY$ = "End Message: S)ave, A)bort, or [C]ontinue? "
  622.       ZHiLiteOff = ZFalse
  623.       CALL ColorPrompt(YY$)
  624.       CALL Puts(YY$, 99, ZTrue)
  625.       CurrentRow = 0
  626.       CurrentCol = 0
  627.       CALL Getch(B$)
  628.       IF ZSubParm <> 0 THEN EXIT SUB
  629.       WHILE INSTR("SAC", B$) = 0 AND INSTR("sac", B$) = 0 AND B$ <> CHR$(27) AND B$ <> CHR$(13)
  630.      CALL Getch(B$)
  631.      IF ZSubParm <> 0 THEN EXIT SUB
  632.       WEND
  633.       IF B$ = CHR$(13) OR B$ = CHR$(27) THEN B$ = "C"
  634.       I = INSTR("SAC", B$)
  635.       IF I = 0 THEN I = INSTR("sac", B$)
  636.       ON I GOTO SaveMsg, AbortMsg, ContinueMsg
  637.       EXIT SUB
  638.  
  639. ContinueMsg:
  640.  
  641.       EXIT SUB
  642.  
  643. AbortMsg:
  644.  
  645.       CALL ClearMainMenu
  646.       CALL QuickTput(ZEmphasizeOff$, 0)
  647.       CurrentRow = 0
  648.       CurrentCol = 0
  649.       CALL MoveCursor(1, 1)
  650.       YY$ = "Abort: Are You Sure (Y)es,[N]o)? "
  651.       ZHiLiteOff = ZFalse
  652.       CALL ColorPrompt(YY$)
  653.       CALL Puts(YY$, 99, ZTrue)
  654.       CurrentRow = 0
  655.       CurrentCol = 0
  656.       CALL Getch(B$)
  657.       IF ZSubParm <> 0 THEN B$ = "Y"
  658.       IF B$ = "Y" OR B$ = "y" THEN
  659.      CALL ClearScreen
  660.      CALL QuickTput(ZEmphasizeOff$, 0)
  661.      ZSubParm = 2
  662.       END IF
  663.       EXIT SUB
  664.  
  665. SaveMsg:
  666.  
  667.       CALL ClearScreen
  668.       FOR I = 99 TO 1 STEP -1
  669.      IF ZOutTxt$(I) <> BlankLine$ THEN
  670.             EndOfMsg = I
  671.         EXIT FOR
  672.      END IF
  673.       NEXT I
  674.       FOR I = 1 TO EndOfMsg
  675.      j = INSTR(ZOutTxt$(I), SoftSpace$)
  676.      WHILE j <> 0
  677.         MID$(ZOutTxt$(I), j, 1) = " "
  678.         j = INSTR(ZOutTxt$(I), SoftSpace$)
  679.      WEND
  680.       NEXT I
  681.       FOR I = EndOfMsg TO 1 STEP -1
  682.          CALL TrimTrail(ZOutTxt$," ")                              ' QB 3.0 Mod
  683.      IF ZOutTxt$(I) <> "" THEN
  684.             EndOfMsg = I
  685.         EXIT FOR
  686.      END IF
  687.       NEXT I
  688.       ZLinesInMsg = EndOfMsg
  689.       CALL QuickTput(ZEmphasizeOff$, 0)
  690.       ZSubParm = 1
  691.       EXIT SUB
  692.  
  693. END SUB
  694.  
  695. '*----------------------------------------------------------------------------*
  696. '*    This routine clears from a position to to the end of that line          *
  697. '*----------------------------------------------------------------------------*
  698. SUB EraseToEOL (LineNumber, ColNumber) STATIC
  699.  
  700.       CALL SaveCursor(RowSave,ColSave)
  701.       CALL MoveCursor(LineNumber, ColNumber)
  702.       YY$ = ""
  703.       CALL Puts(YY$, 99, ZFalse)
  704.       CALL MoveCursor(RowSave, ColSave)
  705.  
  706. END SUB
  707.  
  708. '*----------------------------------------------------------------------------*
  709. '* This routine executes the currently highlighted main menu command          *
  710. '*----------------------------------------------------------------------------*
  711. SUB ExecuteMainMenuCommand (CMD$) STATIC
  712.  
  713. 1100  ZSubParm = 0
  714.       SELECT CASE CMD$
  715.      CASE "H"
  716.         CALL HelpMe
  717.      CASE "E"
  718.         CALL DoneWithMsg
  719.      CASE "P"
  720.         CALL ClearScreen
  721.         CALL UpdateScreen
  722.      CASE "I"
  723.         InsertMode = NOT InsertMode
  724.      CASE "R"
  725.         CALL ReformText(ZFalse)
  726.      CASE "J"
  727.         CALL ReformText(ZTrue)
  728.       END SELECT
  729.       IsBold = 99        ' v2.41
  730.  
  731. END SUB
  732.  
  733. '*----------------------------------------------------------------------------*
  734. '*  This routine finds a place in the string yy$ that could be used as a      *
  735. '*  place to wrap the line WhereToWrap should be the last position that       *
  736. '*  remains in the line, ie                                                   *
  737. '*    set   currentline$ = left$(yy$,wheretowrap)                             *
  738. '*          nextline$    = mid$ (yy$,wheretowrap+1)                           *
  739. '*----------------------------------------------------------------------------*
  740. SUB FindWrap (YY$, WhereToWrap) STATIC
  741.  
  742.       I = LEN(YY$)
  743.       XX$ = " " + SoftSpace$
  744.       
  745.       ' back over "False hits"
  746.       
  747.       ZZ$ = MID$(YY$, I, 1)
  748.       WHILE INSTR(XX$, ZZ$) <> 0 AND I <> 1
  749.      I = I - 1
  750.      ZZ$ = MID$(YY$, I, 1)
  751.       WEND
  752.       
  753.       WHILE INSTR(XX$, ZZ$) = 0 AND I <> 1
  754.      I = I - 1
  755.      ZZ$ = MID$(YY$, I, 1)
  756.       WEND
  757.       WhereToWrap = I
  758.  
  759. END SUB
  760.  
  761. '*----------------------------------------------------------------------------*
  762. '*         This routine reads a character from the user into yy$              *
  763. '*----------------------------------------------------------------------------*
  764. SUB Getch (YY$) STATIC
  765.  
  766.       ZAutoLogoff! = TIMER + ZWaitBeforeDisconnect
  767. 1500  CALL Carrier
  768.       IF ZSubParm = -1 THEN EXIT SUB
  769.       ZSubParm = 0
  770.       IF LEN(ZCommPortStack$) > 0 THEN
  771.      YY$ = LEFT$(ZCommPortStack$, 1)
  772.      ZCommPortStack$ = MID$(ZCommPortStack$, 2)
  773.      EXIT SUB
  774.       ELSEIF ZLocalUser THEN
  775.      CALL FindFKey
  776.      IF ZSubParm < 0 THEN EXIT SUB
  777.      YY$ = ZKeyPressed$
  778.      IF YY$ <> "" THEN EXIT SUB
  779.      GOTO 1500
  780.       ELSE
  781.      CALL EofComm(Char%)       ' v2.2
  782.      IF Char% <> -1 THEN       ' v2.2
  783.         CALL Carrier
  784.         IF ZSubParm = -1 THEN EXIT SUB
  785.         ZSubParm = 0
  786.         CALL GetCom(YY$)
  787.         EXIT SUB
  788.      ELSE
  789.         CALL CheckTime(ZAutoLogoff!, Remain!, 1)
  790.         IF Remain! < 0 THEN
  791.            CALL UpdtCalr("Sleep disconnect", 1)
  792.            ZSubParm = -1
  793.            ZNo = ZTrue
  794.            ZSleepDisconnect = ZTrue
  795.            EXIT SUB
  796.         ELSE
  797.            GOTO 1500
  798.         END IF
  799.      END IF
  800.       END IF
  801.  
  802. END SUB
  803.  
  804. '*----------------------------------------------------------------------------*
  805. '*  This routine provides on-liine help for the user                          *
  806. '*----------------------------------------------------------------------------*
  807. SUB HelpMe STATIC
  808.  
  809. 2400  CALL SaveCursor(RowSave,ColSave)
  810.       CALL ClearScreen
  811.       CALL MoveCursor(1, 2)
  812.       CALL QuickTput(ZEmphasizeOff$, 0)
  813.       CALL BufFile(ZHelpPath$ + "ANSIED.HLP", X)   ' v2.2
  814.       CurrentRow = 0
  815.       CurrentCol = 0
  816.       OldColour = 0                               ' v2.2
  817.       IsBold = 99                                 ' v2.41
  818.       CALL ClearScreen
  819.       FOR I = 1 TO 24
  820.      ZWorkAra$(I) = BlankLine$
  821.       NEXT I
  822.       CALL UpdateScreen
  823.       CALL MoveCursor(ColSave, RowSave)
  824.  
  825. END SUB
  826.  
  827. '*----------------------------------------------------------------------------*
  828. '*  This routine returns ZTrue if ZOutTxt$(I) is the last line in a paragraph *
  829. '*----------------------------------------------------------------------------*
  830. SUB LastParaLine (I, LastLine, Result) STATIC                      ' QB 3.0 Mod
  831.  
  832.    Result = ZFalse
  833.    IF I = LastLine OR I = 99 THEN
  834.       Result = ZTrue
  835.    ELSE
  836.       YY$ = ZOutTxt$(I)
  837.       j = INSTR(YY$, ">")
  838.       IF j = 0 THEN j = 6
  839.       IF j < 5 THEN
  840.      Result = ZTrue
  841.       ELSEIF YY$ = BlankLine$ THEN
  842.      Result = ZTrue
  843.       ELSE
  844.      IF ZOutTxt$(I + 1) = BlankLine$ THEN
  845.         Result = ZTrue
  846.      ELSEIF LEFT$(ZOutTxt$(I + 1), 1) = " " THEN
  847.         Result = ZTrue
  848.      ELSE
  849.         K = INSTR(ZOutTxt$(I + 1), ">")
  850.         IF K <> 0 AND K < 5 THEN Result = ZTrue
  851.      END IF
  852.       END IF
  853.    END IF
  854.  
  855. END SUB                                                            ' QB 3.0 Mod
  856.  
  857. '*----------------------------------------------------------------------------*
  858. '*  This routine moves the cursor to the position spec'd by newcol and        *
  859. '*  newrow and tries to do it with the minimum number of Ansi characters      *
  860. '*----------------------------------------------------------------------------*
  861. SUB MoveCursor (NewRow, Newcol) STATIC
  862.  
  863. 600   IF CurrentRow = NewRow AND CurrentCol = Newcol THEN
  864.      EXIT SUB
  865.       ELSEIF Newcol = 1 AND NewRow = 1 THEN
  866.      YY$ = "f"
  867.       ELSEIF CurrentCol = Newcol THEN
  868.      ' Just the row has changed
  869.      IF NewRow > CurrentRow THEN
  870.         ' Can use the "move down" command
  871.         I = NewRow - CurrentRow
  872.         IF I = 1 THEN
  873.            YY$ = "B"
  874.         ELSE
  875.            YY$ = "" + MID$(STR$(I), 2) + "B"
  876.         END IF
  877.      ELSE
  878.         ' Use the "move up" command
  879.         I = CurrentRow - NewRow
  880.         IF I = 1 THEN
  881.            YY$ = "A"
  882.         ELSE
  883.            YY$ = "" + MID$(STR$(I), 2) + "A"
  884.         END IF
  885.      END IF
  886.       ELSEIF CurrentRow = NewRow THEN
  887.      ' Just the column has changed
  888.      IF Newcol > CurrentCol THEN
  889.         ' Can use the "move forward" command
  890.         I = Newcol - CurrentCol
  891.         IF I = 1 THEN
  892.            YY$ = "C"
  893.         ELSE
  894.            YY$ = "" + MID$(STR$(I), 2) + "C"
  895.         END IF
  896.      ELSE
  897.         ' Use the "move backward" command
  898.         I = CurrentCol - Newcol
  899.         IF I = 1 THEN
  900.            YY$ = "D"
  901.         ELSE
  902.            YY$ = "" + MID$(STR$(I), 2) + "D"
  903.         END IF
  904.      END IF
  905.       ELSE
  906.      ' They both changed
  907.      YY$ = "" + MID$(STR$(NewRow), 2) + ";" + MID$(STR$(Newcol), 2) + "f"
  908.       END IF
  909.       CALL Puts(YY$, 99, ZTrue)
  910.       CurrentRow = NewRow
  911.       CurrentCol = Newcol
  912.  
  913. END SUB
  914.  
  915. '*----------------------------------------------------------------------------*
  916. '*  This routine handles 'normal' characters entered into the message         *
  917. '*----------------------------------------------------------------------------*
  918. SUB NormalChar (YY$) STATIC
  919.  
  920.       CALL SaveCursor(RowSave,ColSave)
  921.       Index = CurrentRow + TopLine - 2
  922.       currentlineblank = (ZOutTxt$(Index) = BlankLine$)
  923.       lbi = LEN(ZOutTxt$(Index))
  924.       
  925.       IF CurrentCol = 80 THEN EXIT SUB
  926.      
  927.       AtEndOfLine = ZFalse
  928.       
  929.       IF CurrentCol > lbi THEN
  930.       
  931.      ZOutTxt$(Index) = ZOutTxt$(Index) + SPACE$(CurrentCol - lbi)
  932.      ZWorkAra$(CurrentRow) = ZWorkAra$(CurrentRow) + SPACE$(CurrentCol - lbi)
  933.      lbi = LEN(ZOutTxt$(Index))
  934.      AtEndOfLine = ZTrue
  935.      
  936.       END IF
  937.  
  938.       IF (CurrentCol <= ZRightMargin AND AtEndOfLine) OR (CurrentCol <= ZRightMargin AND NOT InsertMode) THEN
  939.  
  940.      ' single character changed
  941.         
  942.      MID$(ZOutTxt$(Index), CurrentCol, 1) = YY$
  943.      MID$(ZWorkAra$(CurrentRow), CurrentCol, 1) = YY$
  944.      CALL Puts(YY$, YellowFore, ZTrue)
  945.  
  946.       ELSEIF (NOT AtEndOfLine AND InsertMode AND CurrentCol <= ZRightMargin AND lbi <= ZRightMargin) THEN
  947.  
  948.      ' have to rewrite the screen from the current pos forward
  949.  
  950.      ZOutTxt$(Index) = LEFT$(ZOutTxt$(Index), CurrentCol - 1) + YY$ + MID$(ZOutTxt$(Index), CurrentCol)
  951.             
  952.      ZWorkAra$(CurrentRow) = ZOutTxt$(Index)
  953.                     
  954.      CALL EraseToEOL(CurrentRow, CurrentCol)
  955.      ZZ$ = MID$(ZWorkAra$(CurrentRow), CurrentCol)
  956.      CALL Puts(ZZ$, YellowFore, ZTrue)
  957.      CALL MoveCursor(RowSave, ColSave + 1)
  958.  
  959.       ELSE      '  word wrap time
  960.  
  961.      IF NOT AtEndOfLine THEN
  962.      
  963.         ZOutTxt$(Index) = LEFT$(ZOutTxt$(Index), CurrentCol - 1) + YY$ + MID$(ZOutTxt$(Index), CurrentCol)
  964.         lbi = lbi + 1
  965.         
  966.      ELSE
  967.      
  968.         MID$(ZOutTxt$(Index), CurrentCol, 1) = YY$
  969.                     
  970.      END IF
  971.      
  972.      CALL FindWrap(ZOutTxt$(Index), I)
  973.      IF I = 0 OR I = 1 THEN I = ZRightMargin
  974.  
  975.      ZZ$ = MID$(ZOutTxt$(Index), (I + 1))
  976.      CALL RightTrim(ZZ$)
  977.      ZOutTxt$(Index) = LEFT$(ZOutTxt$(Index), I)
  978.      ' add to the beginning of a new line
  979.      IF Index < 98 THEN Index = Index + 1
  980.      FOR j = 98 TO Index STEP -1
  981.         ZOutTxt$(j + 1) = ZOutTxt$(j)
  982.      NEXT j
  983.      ZOutTxt$(Index) = ZZ$
  984.  
  985.      CALL EraseToEOL(CurrentRow, I + 1) ' do the "easy" line
  986.      ZWorkAra$(CurrentRow) = ZOutTxt$(Index)
  987.  
  988.      CALL UpdateScreen
  989.      IF (ColSave > I) THEN
  990.         Newcol = ColSave - I + 1
  991.         IF RowSave <> 23 THEN
  992.            CALL MoveCursor(RowSave + 1, Newcol)
  993.         ELSE
  994.            CALL MoveCursor(RowSave, Newcol)
  995.            CALL Ungetch(LineDownKey$)
  996.         END IF
  997.      ELSE
  998.         CALL MoveCursor(RowSave, ColSave + 1)
  999.      END IF
  1000.       END IF
  1001.  
  1002. END SUB
  1003.  
  1004. '*----------------------------------------------------------------------------*
  1005. '*  This routine removes soft spaces from the string specified                *
  1006. '*----------------------------------------------------------------------------*
  1007. SUB NoSoft (YY$) STATIC
  1008.  
  1009.       I = INSTR(YY$, SoftSpace$)
  1010.       WHILE I <> 0
  1011.      YY$ = LEFT$(YY$, I - 1) + MID$(YY$, I + 1)
  1012.      I = INSTR(YY$, SoftSpace$)
  1013.       WEND
  1014.  
  1015. END SUB
  1016.  
  1017. '*----------------------------------------------------------------------------*
  1018. '* This routine writes yy$ to the user in the color and intensity specified   *
  1019. '*----------------------------------------------------------------------------*
  1020. SUB Puts (YY$, Colour, Bold) STATIC
  1021.  
  1022.       ZZ$ = ""
  1023.       IF Colour <> 99 THEN
  1024.      IF (Colour <> OldColour) OR (Bold <> IsBold) THEN ' v2.41
  1025.          
  1026.         ZZ$ = ""
  1027.         
  1028.         IF Bold <> IsBold THEN       ' v2.41
  1029.            IF Bold THEN              ' v2.41
  1030.           ZZ$ = ZZ$ + "1;"       ' v2.41
  1031.           IsBold = ZTrue         ' v2.41
  1032.            ELSE                      ' v2.41
  1033.           ZZ$ = ZZ$ + "0;"       ' v2.41
  1034.           IsBold = ZFalse        ' v2.41
  1035.            END IF                    ' v2.41
  1036.         END IF                       ' v2.41
  1037.            
  1038.         ZZ$ = ZZ$ + MID$(STR$(Colour), 2)
  1039.         ZZ$ = ZZ$ + "m"
  1040.      END IF
  1041.       END IF
  1042.       ZZ$ = ZZ$ + YY$
  1043.  
  1044.       ZOutTxt$ = ZZ$
  1045.       ZSubParm = 4
  1046.       CALL Tput
  1047.       ZSubParm = 0
  1048.  
  1049.       IF INSTR(YY$, "") = 0 THEN
  1050.      CurrentCol = CurrentCol + LEN(YY$)
  1051.      IF CurrentCol > 80 THEN Col = 80
  1052.       END IF
  1053.       OldColour = Colour
  1054.       Colour = 99
  1055.  
  1056. END SUB
  1057.  
  1058. '*----------------------------------------------------------------------------*
  1059. '*  This routine reformats the text file to the current margins               *
  1060. '*----------------------------------------------------------------------------*
  1061. SUB ReformText (Justify%) STATIC
  1062.  
  1063. 2201  CALL SaveCursor(RowSave,ColSave)
  1064.  
  1065.       DIM SpacePlace(80)
  1066.  
  1067.       CALL ClearMainMenu
  1068.       CALL MoveCursor(1, 1)
  1069.       CALL Puts("Reformatting...", YellowFore, ZTrue)
  1070.  
  1071.       LastLine = 1
  1072.       FOR I = 99 TO 1 STEP -1
  1073.      IF ZOutTxt$(I) <> BlankLine$ THEN
  1074.         LastLine = I
  1075.         EXIT FOR
  1076.      END IF
  1077.       NEXT
  1078.  
  1079.       I = 1   ' Read index
  1080.       j = 1   ' Write index
  1081.  
  1082.       ' Reflow the text to the maximum on a line
  1083.  
  1084.       DO WHILE I <= LastLine
  1085.      ZOutTxt$ = ""
  1086.      DO WHILE 1
  1087.         YY$ = ZOutTxt$(I)
  1088.         CALL NoSoft(YY$)
  1089.         IF ZOutTxt$ <> "" AND RIGHT$(ZOutTxt$, 1) <> " " THEN ZOutTxt$ = ZOutTxt$ + " "
  1090.         ZOutTxt$ = ZOutTxt$ + YY$
  1091.             CALL LastParaLine(I, LastLine, Z)                      ' QB 3.0 Mod
  1092.         IF LEN(ZOutTxt$) > ZRightMargin OR Z THEN
  1093.            IF LEN(ZOutTxt$) > ZRightMargin THEN
  1094.           CALL FindWrap(LEFT$(ZOutTxt$, ZRightMargin + 1), K)
  1095.           IF K = 0 OR K = 1 THEN K = ZRightMargin
  1096.           ZOutTxt$(j) = LEFT$(ZOutTxt$, K)
  1097.           IF Z THEN
  1098.              ' Go to the next paragraph
  1099.              ZOutTxt$(j + 1) = MID$(ZOutTxt$, K + 1)
  1100.              j = j + 2
  1101.              I = I + 1
  1102.              EXIT DO
  1103.           ELSE
  1104.              ZOutTxt$(I) = MID$(ZOutTxt$, K + 1)
  1105.              j = j + 1
  1106.              EXIT DO
  1107.           END IF
  1108.            ELSE          ' Z is ZTrue
  1109.           ZOutTxt$(j) = ZOutTxt$
  1110.           j = j + 1
  1111.           I = I + 1
  1112.           EXIT DO
  1113.            END IF
  1114.         ELSE
  1115.            I = I + 1
  1116.         END IF
  1117.      LOOP
  1118.       LOOP
  1119.  
  1120.       FOR I = j TO 99
  1121.      ZOutTxt$(I) = BlankLine$
  1122.       NEXT
  1123.  
  1124.       LastLine = j - 1
  1125.  
  1126.       ' Now space out the text on each line
  1127.       IF Justify% THEN
  1128.      FOR I = 1 TO LastLine
  1129.             CALL LastParaLine(I, LastLine, Z)                      ' QB 3.0 Mod
  1130.             IF Z THEN
  1131.         ELSE
  1132.            ZOutTxt$ = ZOutTxt$(I)
  1133.            ' Find out all of the possible places to put spaces
  1134.                CALL TrimTrail(ZOutTxt$," ")                        ' QB 3.0 Mod
  1135.            ' Skip leading spaces
  1136.            FOR K = 1 TO LEN(ZOutTxt$)
  1137.           IF MID$(ZOutTxt$, K, 1) <> " " THEN EXIT FOR
  1138.            NEXT
  1139.            L = 0
  1140.            FOR K = K TO LEN(ZOutTxt$)
  1141.           IF MID$(ZOutTxt$, K, 1) = " " THEN L = L + 1
  1142.            NEXT
  1143.            IF L <> 0 THEN
  1144.           FOR K = 1 TO LEN(ZOutTxt$)
  1145.              IF MID$(ZOutTxt$, K, 1) <> " " THEN EXIT FOR
  1146.           NEXT
  1147.           L = 1
  1148.           FOR K = K TO LEN(ZOutTxt$)
  1149.              IF MID$(ZOutTxt$, K, 1) = " " THEN
  1150.             SpacePlace(L) = K
  1151.             L = L + 1
  1152.              END IF
  1153.           NEXT
  1154.           L = L - 1
  1155.           ' Space it out
  1156.           SpacesToAdd = ZRightMargin - LEN(ZOutTxt$)
  1157.           M = 1
  1158.           N = L
  1159.           DoM = ZTrue
  1160.           WHILE SpacesToAdd <> 0
  1161.              IF DoM THEN
  1162.             Place = SpacePlace(M)
  1163.             M = M + 1
  1164.              ELSE
  1165.             Place = SpacePlace(N)
  1166.             N = N - 1
  1167.              END IF
  1168.              DoM = NOT DoM
  1169.              ZOutTxt$(I) = LEFT$(ZOutTxt$(I), Place) + SoftSpace$ + MID$(ZOutTxt$(I), Place + 1)
  1170.              SpacesToAdd = SpacesToAdd - 1
  1171.              FOR P = 1 TO L
  1172.             IF SpacePlace(P) > Place THEN
  1173.                SpacePlace(P) = SpacePlace(P) + 1
  1174.             END IF
  1175.              NEXT
  1176.              IF M = N THEN
  1177.             M = 1
  1178.             N = L
  1179.              END IF
  1180.           WEND
  1181.            END IF
  1182.         END IF
  1183.      NEXT
  1184.       END IF
  1185.  
  1186.       CALL UpdateScreen
  1187.       CALL MoveCursor(ColSave, RowSave)
  1188.  
  1189. END SUB
  1190.  
  1191. '*----------------------------------------------------------------------------*
  1192. '*   Removes soft spaces from a string                                        *
  1193. '*----------------------------------------------------------------------------*
  1194. SUB RightTrim (YY$) STATIC
  1195.  
  1196.       FOR I = LEN(YY$) TO 1 STEP -1
  1197.      IF MID$(YY$, I, 1) <> SoftSpace$ THEN
  1198.         YY$ = LEFT$(YY$, I)
  1199.         EXIT SUB
  1200.      END IF
  1201.       NEXT I
  1202.       YY$ = ""
  1203.  
  1204. END SUB
  1205.  
  1206. '*----------------------------------------------------------------------------*
  1207. '*   Puts a key in the beginning of the keyboard buffer                       *
  1208. '*----------------------------------------------------------------------------*
  1209. SUB Ungetch (YY$) STATIC
  1210.  
  1211.       ZCommPortStack$ = YY$ + ZCommPortStack$
  1212.  
  1213. END SUB
  1214.  
  1215. '*----------------------------------------------------------------------------*
  1216. '*  This is one of the most important routines  It compares the arrays        *
  1217. '*  ZOutTxt$ and ZWorkAra$ and only sends the user the DIFFERENCE between the *
  1218. '*  two within the viewing area  In this way all processing can be done on    *
  1219. '*  ZOutTxt$ and then the screen is updated to reflect the changes After the  *
  1220. '*  users screen is updated, ZWorkAra$ is changed to reflect what should be   *
  1221. '*  on the users' screen The cursor is restored to its original position      *
  1222. '*----------------------------------------------------------------------------*
  1223. SUB UpdateScreen STATIC
  1224.  
  1225.       CALL SaveCursor(RowSave,ColSave)
  1226.  
  1227.       CurrentRow = 0
  1228.       CurrentCol = 0
  1229.  
  1230.       FOR I = 2 TO 23
  1231.  
  1232.      Index = I + TopLine - 2
  1233.      scri$ = ZWorkAra$(I)
  1234.      bufind$ = ZOutTxt$(Index)
  1235.      lbi = LEN(bufind$)
  1236.      lsi = LEN(scri$)
  1237.  
  1238.      IF bufind$ = scri$ THEN
  1239.         ' Do Nothing
  1240.      ELSEIF bufind$ = BlankLine$ OR bufind$ = SPACE$(lbi) THEN
  1241.         CALL ClearLine(I)
  1242.         ZWorkAra$(I) = bufind$
  1243.      ELSE
  1244.         CALL MoveCursor(I, 1)
  1245.         YY$ = bufind$
  1246.         CALL Puts(YY$, YellowFore, ZTrue)
  1247.         CALL EraseToEOL(CurrentRow, CurrentCol)
  1248.         ZWorkAra$(I) = ZOutTxt$(Index)
  1249.      END IF
  1250.       NEXT I
  1251.       CALL MoveCursor(RowSave, ColSave)
  1252.  
  1253. END SUB
  1254.  
  1255. '*----------------------------------------------------------------------------*
  1256. '*  This routine rewrites the status line on screen line 1                    *
  1257. '*----------------------------------------------------------------------------*
  1258. SUB UpdateStatusLine STATIC
  1259.  
  1260.       CurrentRow = 0
  1261.       CurrentCol = 0
  1262. 1000  CALL MoveCursor(1, 1)
  1263.       YY$ = "ANSIED v2.42 by Tom Collins  "
  1264.       IF InsertMode THEN
  1265.      YY$ = YY$ + "   Insert  "
  1266.       ELSE
  1267.      YY$ = YY$ + "  Overwrite"
  1268.       END IF
  1269.       YY$ = YY$ + "  - Press ESC Twice For Menu -"
  1270.       YY$ = YY$ + SPACE$(80 - LEN(YY$))
  1271.       CALL Puts(YY$, CyanFore, ZFalse)
  1272.  
  1273. END SUB
  1274.  
  1275. '*----------------------------------------------------------------------------*
  1276. '*  This routine saves the current cursor position                            *
  1277. '*----------------------------------------------------------------------------*
  1278. SUB SaveCursor (Row%, Col%) STATIC
  1279.  
  1280.    Row% = CurrentRow
  1281.    Col% = CurrentCol
  1282.  
  1283. END SUB
  1284.